import request from '@/utils/request'

export const productGetListService = () => {
  return request.get('/product/api/public');
}

export const productGetDetailServcie = (productId) => {
  return request.get(`/product/api/public/detail/${productId}`);
}

export const productGetMerchantProductService = () => {
  return request.get('/product/api/me/merchant');
}

export const productGetMerchantProductEditService = (productId) => {
  return request.get(`/product/api/me/merchant/edit/${productId}`);
}

export const productPostSkuSpecService = ({productId, type, spec, skus}) => {
  return request.post('/product/api/me/merchant/sku/spec', {productId, type, spec, skus});
}

export const productPostProductCarouselService = (productId, file) => {
  const formData = new FormData();
  formData.set('carouselFile', file);

  return request.post(`/product/api/me/merchant/carousel/${productId}`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

export const productDeleteProductCarouselService = (productId, carouselId) => {
  return request.delete(`/product/api/me/merchant/carousel/${productId}/${carouselId}`);
}

export const productDeleteMerchantProductService = (productId) => {
  return request.delete(`/product/api/me/merchant/${productId}`);
}

export const productPutMerchantProductBasicInfoService = (productId, basicData) => {
  const formData = new FormData();
  for (const key in basicData) {
    formData.append(key, basicData[key]);
  }
  
  return request.put(`/product/api/me/merchant/${productId}`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

export const productPutMerchantProductSkuService = (changeSkuList) => {
  return request.put(`/product/api/me/merchant/sku`, {changeSkuList});
}

export const productPostMerchantProductService = (basicData) => {
  const formData = new FormData();
  for (const key in basicData) {
    formData.append(key, basicData[key]);
  }

    return request.post('/product/api/me/merchant', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}